package com.mengwen.backstage.service.impl;

import com.mengwen.backstage.mapper.GetNotificationMapper;
import com.mengwen.backstage.pojo.GetNotification;
import com.mengwen.backstage.service.GetNotificationService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.swing.*;
import java.util.List;

/**
 * @author LiangYonghui
 * @date 2020/4/8 18:47
 * @description 获取通知的业务接口实现类
 */
@Service
public class GetNotificationServiceImpl implements GetNotificationService {
    private static final Log LOG = LogFactory.getLog(GetNotificationServiceImpl.class);

    @Autowired
    GetNotificationMapper getNotificationMapper;
    @Override
    public List<GetNotification> findNotReadNotificationByUnionid(String unionid) {
        List<GetNotification> notifications = getNotificationMapper.findNotReadNotificationByUnionid(unionid);
        if (notifications != null) { // 设为已读
            int count = getNotificationMapper.setReadByUnionid(unionid);
            if (count == -1) {
                LOG.info("设置已读失败,unionid：" + unionid);
            }
            return notifications;
        }else {
            return notifications;
        }

    }
}
